package com.ggh.jinjilive.ui.mall.order;

import androidx.databinding.ObservableField;
import androidx.lifecycle.MutableLiveData;

import com.ggh.jinjilive.mobile.Pay.WeChatPayMobile;
import com.ggh.jinjilive.mobile.ResultEntity;
import com.ggh.jinjilive.mobile.mall.MallPointsClass;
import com.ggh.jinjilive.mobile.mall.order.MineOrder;
import com.ggh.jinjilive.mobile.mall.shopping.ShopMessageMoblie;
import com.ggh.jinjilive.remotedata.InterceptObserver;
import com.ggh.jinjilive.remotedata.systemapi.SystemApiService;
import com.ggh.jinjilive.ui.BaseViewModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

public class OrderViewModel extends BaseViewModel {
    //订单数据
    public MutableLiveData<List<MineOrder>> mMineOrderList = new MutableLiveData<>();
    //微信付款信息
    public MutableLiveData<WeChatPayMobile> mWeChatPayMobile = new MutableLiveData<>();
    //支付宝付款信息
    public MutableLiveData<String> mAlipayString = new MutableLiveData<>();

    public OrderViewModel(SystemApiService apiCallInterface) {
        super(apiCallInterface);

    }

    /**
     * 获取订单信息
     * @param status
     */
    public void orderList(int status,int type){
        if (isRefresh) {
            page = 1;
        }else {
            page = page + 1;
        }
        Map<String, Object> map = new HashMap<>();
        map.put("page",page);
        map.put("status",status);
        map.put("type",type);
        addSubscribe(apiCallInterface.orderList(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<List<MineOrder>>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                List<MineOrder> mineOrderList = (List<MineOrder>) resultEntity.getData();
                mMineOrderList.setValue(mineOrderList);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {

            }
        }));
    }


    /**
     * 微信付款信息
     * @param map
     */
    public void weChatpayOrder(Map<String, Object> map){
        addSubscribe(apiCallInterface.weChatpayOrder(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<WeChatPayMobile>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                WeChatPayMobile weChatPayMobile = (WeChatPayMobile) resultEntity.getData();
                mWeChatPayMobile.setValue(weChatPayMobile);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {
            }
        }));
    }

    /**
     * 支付宝付款信息
     * @param map
     */
    public void alipayPayOrder(Map<String, Object> map){
        addSubscribe(apiCallInterface.alipayPayOrder(map).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new InterceptObserver<ResultEntity<String>>() {
            @Override
            public void onNextData(ResultEntity resultEntity) {
                String alipayString = (String) resultEntity.getData();
                mAlipayString.setValue(alipayString);
            }

            @Override
            public void onErrorNet(Throwable t, String netMsg) {
            }
        }));
    }
}
